package com.caizongzhen.www.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.caizongzhen.www.entity.Medicine;
import com.caizongzhen.www.mapper.MedicineMapper;
import com.caizongzhen.www.util.Assert;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MedicineService  extends ServiceImpl<MedicineMapper, Medicine> {
    public static int total;
    public List<Medicine> findMedicineByName(String medicineName){
        List<Medicine> medicineList = new ArrayList<>();
        QueryWrapper queryWrapper = new QueryWrapper();
        if(Assert.isEmpty(medicineName)) {
            medicineList = this.list();
        }
        else {
            queryWrapper.like(medicineName !=null,"medicine_name",medicineName);
            medicineList = this.baseMapper.selectList(queryWrapper);
        }
        total = medicineList.size();
        return medicineList;
    }
}

